/**
 * JAVACC DEMO 1.0
 * @copy right iussoft company All rights reserved.
 * @Package com.iussoft.portal.send.method
 */
package com.apache.portal.common.template.method;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

import com.apache.tools.StrUtil;
import com.apache.uct.common.ToolsUtil;

import freemarker.template.TemplateMethodModel;
import freemarker.template.TemplateModelException;

/**
 * description:  格式化Long类型时间
 */
public class StringNullMethod implements TemplateMethodModel {

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see freemarker.template.TemplateMethodModel#exec(java.util.List)  
	 */
	public Object exec(List arguments) throws TemplateModelException {
		if (!ToolsUtil.isEmpty(arguments)) {
			String str = String.valueOf(arguments.get(0));
			if (StrUtil.isNull(str)) {
				return "";
			}
			return str;
		}
		return "";
	}

	private String long2TimezoneDefault(Long timer, String simpleFormat) {
		if (timer == null || "".equals(timer))
			return null;
		if (ToolsUtil.isNull(simpleFormat))
			simpleFormat = "yyyy-MM-dd HH:mm:ss";
		String diffTime = TimeZone.getDefault().getID();
		TimeZone tz = TimeZone.getTimeZone(diffTime);
		SimpleDateFormat sdf = new SimpleDateFormat(simpleFormat);
		sdf.setTimeZone(tz);
		Calendar calendar = Calendar.getInstance(tz);
		int offset = calendar.getTimeZone().getRawOffset();
		Date date = new Date(timer + offset);
		return sdf.format(date);
	}

}
